<template>
<view class="shouye">
 	<view class="shoutop">
		 <view class="city" @click="goaita()">
			 {{city}}▼
		 </view>
		 <view class="sear">
 		<u-search placeholder="日照香炉生紫烟" v-model="keyword"></u-search>
 		</view>
 	</view>
	<u-button type="success" @click="getuserinfo()">获取用户信息</u-button>
	<button
	  open-type="getAuthorize"
	  scope="phoneNumber"
	  @click="getPhoneNumber()"
	  onError="handleAuthError"
	>
	  授权手机号
	</button>
	<button
	  open-type="getAuthorize"
	  scope="userInfo"
	  @click="getOpenUserInfo()"
	  onError="handleAuthError"
	>
	  会员基础信息授权
	</button>
	
<button open-type="getAuthorize" scope="IDNumber" @getAuthorize="getIDNumber" @error="errorIDNumber">getAuthorize授权身份证号</button>

	
</view>
</template>

<script>
	import homeApi from '@/api/home'
	export default {
		data() {
			return {
			  canIUseAuthButton: my.canIUse('button.open-type.getAuthorize'),
				title: 'Hello',
				value:"",
				city:"",
				       text1: 'uView UI众多组件覆盖开发过程的各个需求，       组件功能丰富，多端兼容。让您快速集成，开箱即用',
				show:false,
					keyword: '遥看瀑布挂前川'
			}
		},
		onLoad() {
   // this.gethosjiuyi()
   this.getlocation()
		},
		methods: {
			// 授权身份证号
			getIDNumber () {
				wx.getIDNumber({
					success: async (res) => {
						console.log('授权成功',res)
					},
					fail: (err) => {
						console.log('授权失败',err)
					}
				})
			},
			// 拒绝身份证号
			errorIDNumber(e){
				console.log('拒绝授权',e)
			},
			
			 getOpenUserInfo() {
			        my.getOpenUserInfo({
			            success: (res) => {
			                let userInfo = JSON.parse(res.response).response
							console.log(userInfo)
			            },
			            fail: (err) => {
			                console.log(err)
			            }
			        });
			    },
			getPhoneNumber() {
				console.log(123)
			    my.getPhoneNumber({
			      success: (res) => {
			        let encryptedData = res.response;
					console.log(encryptedData)
			        // my.request({
			        //   //你的服务器地址
			        //   url: 'https://xxxxxxx',
			        //   data: encryptedData,
			        // });
			      },
			      fail: (res) => {
			        console.log(res);
			      },
			    });
			  },
			getuserinfo(){
				 my.getAuthCode({
				      scopes: 'auth_user',
				      success: res => {
				        const authCode = res.authCode;
						console.log(authCode,"这是唯一标识")
				        // 在服务端获取用户信息
				        // my.request({
				        //   // 你的服务器地址
				        //   url: 'https://yourserveraddress',
				        //   data: {
				        //     authCode,
				        //   },
				        //   success(res) {
				        //     // 获取需要的用户信息
				        //     console.log(res)
				        //   }
				        // })
				      },
				      fail: err => {
				        console.log('my.getAuthCode 调用失败', err)
				      }
				    });
			},
			close(){
				this.show=false
			},
			goaita(){
			uni.navigateTo({
				url:"../sousuo/sousuo"
			})
			},
			getlocation(){
				my.getLocation({
				  type: 1, // 获取经纬度和省市区县数据
				  success: (res) => {
				    console.log(res);
					uni.showToast({
						title:res.city
					})
					this.city=res.city
				  },
				  fail: (res) => {
				    my.alert({ title: '定位失败', content: JSON.stringify(res) });
				  },
				  complete: () => {},
				});
			},

		}
	}
</script>

<style lang="scss">
	.shouye{
		padding-top: 50rpx;
		.shoutop{
			width: 90%;
			margin: 0 auto;
			display: flex;
			justify-content: space-between;
			.city{
				width: 20%;
				font-size: 28rpx;
				line-height: 70rpx;
			}
			.sear{
				width: 80%;
			}
		}
	}
</style>
